home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / winsock / ircii2-6.zip / SRC\IRCII-2.6\SOURCE\NOTIFY.C < prev    next >
C/C++ Source or Header  |  1994-12-31  |  6KB  |  280 lines

  1. /*
  2.  * notify.c: a few handy routines to notify you when people enter and leave irc 
  3.  *
  4.  * Written By Michael Sandrof
  5.  * Copyright(c) 1990 
  6.  * See the COPYRIGHT file, or do a HELP IRCII COPYRIGHT 
  7.  *
  8.  * Revamped by lynX - Dec '91
  9.  */
  10.  
  11. #ifndef lint
  12. static    char    rcsid[] = "@(#)$Id: notify.c,v 1.12 1994/09/03 13:53:40 mrg Stab $";
  13. #endif
  14.  
  15. #include "irc.h"
  16.  
  17. #include "list.h"
  18. #include "notify.h"
  19. #include "ircaux.h"
  20. #include "whois.h"
  21. #include "hook.h"
  22. #include "server.h"
  23. #include "output.h"
  24. #include "vars.h"
  25.  
  26. /* NotifyList: the structure for the notify stuff */
  27. typedef    struct    notify_stru
  28. {
  29.     struct    notify_stru    *next;    /* pointer to next notify person */
  30.     char    *nick;            /* nickname of person to notify about */
  31.     int    flag;            /* 1=person on irc, 0=person not on irc */
  32. }    NotifyList;
  33.  
  34. static    NotifyList    *notify_list = (NotifyList *) 0;
  35.  
  36. extern void    ison_notify();
  37.  
  38. /* Rewritten, -lynx */
  39. void
  40. show_notify_list(all)
  41.     int    all;
  42. {
  43.     NotifyList    *tmp;
  44.     char    *list = (char *) 0;
  45.  
  46.     malloc_strcpy(&list, empty_string);
  47.     for (tmp = notify_list; tmp; tmp = tmp->next)
  48.     {
  49.         if (tmp->flag)
  50.         {
  51.             malloc_strcat(&list, " ");
  52.             malloc_strcat(&list, tmp->nick);
  53.         }
  54.     }
  55.     if (*list)
  56.         say("Currently present:%s", list);
  57.     if (all)
  58.     {
  59.         malloc_strcpy(&list, empty_string);
  60.         for (tmp = notify_list; tmp; tmp = tmp->next)
  61.         {
  62.             if (!(tmp->flag))
  63.             {
  64.                 malloc_strcat(&list, " ");
  65.                 malloc_strcat(&list, tmp->nick);
  66.             }
  67.         }
  68.         if (*list) say("Currently absent:%s", list);
  69.     }
  70.     new_free(&list);
  71. }
  72.  
  73. /* notify: the NOTIFY command.  Does the whole ball-o-wax */
  74. /*ARGSUSED*/
  75. void
  76. notify(command, args)
  77.     char    *command,
  78.         *args;
  79. {
  80.     char    *nick,
  81.         *list = (char *) 0,
  82.         *ptr;
  83.     int    no_nicks = 1;
  84.     int    do_ison = 0;
  85.     NotifyList    *new;
  86.  
  87.     malloc_strcpy(&list, empty_string);
  88.     while ((nick = next_arg(args, &args)) != NULL)
  89.     {
  90.         no_nicks = 0;
  91.         while (nick)
  92.         {
  93.             if ((ptr = index(nick, ',')) != NULL)
  94.                 *ptr++ = '\0';
  95.             if (*nick == '-')
  96.             {
  97.                 nick++;
  98.                 if (*nick)
  99.                 {
  100.                     if ((new = (NotifyList *) remove_from_list(¬ify_list, nick)) != NULL)
  101.                     {
  102.                         new_free(&(new->nick));
  103.                         new_free(&new);
  104.                         say("%s removed from notification list", nick);
  105.                     }
  106.                     else
  107.                         say("%s is not on the notification list", nick);
  108.                 }
  109.                 else
  110.                 {
  111.                     for (;(new = notify_list);)
  112.                     {
  113.                         notify_list = new->next;
  114.                         new_free(&new->nick);
  115.                         new_free(&new);
  116.                     }
  117.                     say("Notify list cleared");
  118.                 }
  119.             }
  120.             else
  121.             {
  122.                 /* compatibility */
  123.                 if (*nick == '+')
  124.                     nick++;
  125.                 if (*nick)
  126.                 {
  127.                     do_ison = 1;
  128.                     if (index(nick, '*'))
  129.                         say("Wildcards not allowed in NOTIFY nicknames!");
  130.                     else
  131.                     {
  132.                         if ((new = (NotifyList *) remove_from_list(¬ify_list, nick)) != NULL)
  133.                         {
  134.                             new_free(&(new->nick));
  135.                             new_free(&new);
  136.                         }
  137.                         new = (NotifyList *) new_malloc(sizeof(NotifyList));
  138.                         new->nick = (char *) 0;
  139.                         malloc_strcpy(&(new->nick), nick);
  140.                         new->flag = 0;
  141.                         add_to_list(¬ify_list, new);
  142.                         from_server = primary_server;
  143.                         if (get_server_2_6_2(from_server))
  144.                         {
  145.                             malloc_strcat(&list, new->nick);
  146.                             malloc_strcat(&list, " ");
  147.                         }
  148.                         else
  149.                             add_to_whois_queue( new->nick, whois_notify, (char *) 0);
  150.                         say("%s added to the notification list", nick);
  151.                     }
  152.                 } else
  153.                     show_notify_list(0);
  154.             }
  155.             nick = ptr;
  156.         }
  157.     }
  158.     if (do_ison)
  159.         add_ison_to_whois(list, ison_notify);
  160.     new_free(&list);
  161.     if (no_nicks)
  162.         show_notify_list(1);
  163. }
  164.  
  165. /*
  166.  * do_notify: This simply goes through the notify list, sending out a WHOIS
  167.  * for each person on it.  This uses the fancy whois stuff in whois.c to
  168.  * figure things out.  Look there for more details, if you can figure it out.
  169.  * I wrote it and I can't figure it out.
  170.  *
  171.  * Thank you Michael... leaving me bugs to fix :) Well I fixed them!
  172.  */
  173. void
  174. do_notify()
  175. {
  176.     static    int    location = 0;
  177.     int    count,
  178.         c2;
  179.     define_big_buffer(buf);
  180.     NotifyList    *tmp;
  181.  
  182.     *buf = '\0';
  183.     from_server = primary_server;
  184.     for (tmp = notify_list, c2 = count = 0; tmp; tmp = tmp->next, count++)
  185.     {
  186.         if (count >= location && count < location + 40)
  187.         {
  188.             c2++;
  189.             strcat(buf, " ");
  190.             strcat(buf, tmp->nick);
  191.         }
  192.     }
  193.     if (c2)
  194.         add_ison_to_whois(buf, ison_notify);
  195.     if ((location += 40) > count)
  196.         location = 0;
  197.     free_big_buffer(buf);
  198. }
  199.  
  200. /*
  201.  * notify_mark: This marks a given person on the notify list as either on irc
  202.  * (if flag is 1), or not on irc (if flag is 0).  If the person's status has
  203.  * changed since the last check, a message is displayed to that effect.  If
  204.  * the person is not on the notify list, this call is ignored 
  205.  * doit if passed as 0 means it comes from a join, or a msg, etc, not from
  206.  * an ison reply.  1 is the other..
  207.  */
  208. void
  209. notify_mark(nick, flag, doit)
  210.     char    *nick;
  211.     int    flag;
  212.     int    doit;
  213. {
  214.     NotifyList    *tmp;
  215.     char    *s = get_string_var(NOTIFY_HANDLER_VAR);
  216.  
  217.     if (!doit && 'O' == *s)        /* old notify */
  218.         return;    
  219.     if ('N' == *s)            /* noisy notify */
  220.         doit = 1;
  221.     if ((tmp = (NotifyList *) list_lookup(¬ify_list, nick,
  222.             !USE_WILDCARDS, !REMOVE_FROM_LIST)) != NULL)
  223.     {
  224.         if (flag)
  225.         {
  226.             if (tmp->flag != 1)
  227.             {
  228.                 if (tmp->flag != -1 && do_hook(NOTIFY_SIGNON_LIST, "%s", nick) && doit)
  229.                     say("Signon by %s detected", nick);
  230.                 /*
  231.                  * copy the correct case of the nick
  232.                  * into our array  ;)
  233.                  */
  234.                 malloc_strcpy(&(tmp->nick), nick);
  235.                 malloc_strcpy(&last_notify_nick, nick);
  236.                 tmp->flag = 1;
  237.             }
  238.         }
  239.         else
  240.         {
  241.             if (tmp->flag == 1 && do_hook(NOTIFY_SIGNOFF_LIST, "%s", nick) && doit)
  242.                 say("Signoff by %s detected", nick);
  243.             tmp->flag = 0;
  244.         }
  245.     }
  246. }
  247.  
  248. void
  249. save_notify(fp)
  250.     FILE    *fp;
  251. {
  252.     NotifyList    *tmp;
  253.  
  254.     if (notify_list)
  255.     {
  256.         fprintf(fp, "NOTIFY");
  257.         for (tmp = notify_list; tmp; tmp = tmp->next)
  258.             fprintf(fp, " %s", tmp->nick);
  259.         fprintf(fp, "\n");
  260.     }
  261. }
  262.  
  263. /* I hate broken compilers -mrg */
  264. static    char    *vals[] = { "NOISY", "QUIET", "OLD", (char *) 0 };
  265.  
  266. void
  267. set_notify_handler(value)
  268.     char    *value;
  269. {
  270.     int    len = strlen(value);
  271.     int    i;
  272.     char    *s;
  273.  
  274.     for (i = 0; (s = vals[i]); i++)
  275.         if (0 == my_strnicmp(value, s, len))
  276.             break;
  277.     set_string_var(NOTIFY_HANDLER_VAR, s);
  278.     return;
  279. }
  280.